package com.pet.pet04item.controller;

import com.pet.pojo.Item;
import com.pet.pojo.User;
import com.pet.service.BuyService;
import com.pet.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/buy")
public class BuyController {
    private String userName; //用户名
    private Integer itemId; //商品id
    private Integer num; //商品数量
    @Autowired
    private BuyService buyService;
    /*点击购买，获取用户名和商品id保存在此处*/
    @PostMapping("/setBuy")
    public void setBuy(String userName,Integer itemId,Integer num){
        this.userName = userName;
        this.itemId = itemId;
        this.num = num;
        System.out.println(userName);
        System.out.println(this.itemId);
        System.out.println(this.num);
    }
    /*获取用户信息*/
    @GetMapping("/getUser")
    public SysResult getUser(){
        User user = buyService.getUser(userName);
        return SysResult.success(user);
    }
    /*获取商品信息*/
    @GetMapping("/getItem")
    public SysResult getItem(){
        Item item = buyService.getItem(itemId);
        return SysResult.success(num.toString(),item);
    }
}
